#include <algorithm>
#include <cctype>
#include <cstdio>

typedef long long ll;

const int N = 505, mod = 1e9 + 7;
int n, k, top, stk[N], ch[N][2], f[N][N], a[N], fact[1000005], siz[N];

inline int read() {
  int ch = getchar(), x = 0;
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return x;
}

inline int qpow(ll base, int exp) {
  ll res = 1;
  while (exp) {
    if (exp & 1) res = res * base % mod;
    base = base * base % mod;
    exp >>= 1;
  }
  return res;
}

inline ll C(ll n, ll m) {
  return n < m ? 0
               : 1ll * fact[n] * qpow(fact[n - m], mod - 2) % mod *
                     qpow(fact[m], mod - 2) % mod;
}

void dfs(int x, int t) {
  f[x][0] = 1, siz[x] = 1;
  for (int i = 0; i < 2; ++i) {
    if (ch[x][i]) {
      dfs(ch[x][i], a[x]);
      siz[x] += siz[ch[x][i]];
      for (int j = std::min(siz[x], k); ~j; --j)
        for (int l = 1; l <= std::min(siz[ch[x][i]], j); ++l)
          f[x][j] = (f[x][j] + 1ll * f[ch[x][i]][l] * f[x][j - l] % mod) % mod;
    }
  }
  for (int i = std::min(siz[x], k); ~i; --i) {
    for (int j = 1; j <= std::min(a[x] - t, i); ++j) {
      f[x][i] = (f[x][i] + 1ll * f[x][i - j] * fact[j] % mod * C(a[x] - t, j) % mod *
                               C(siz[x] - (i - j), j) % mod) %
                mod;
    }
  }
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("SP3734(CarTree).in", "r", stdin);
  freopen("SP3734(CarTree).out", "w", stdout);
#endif
#endif

  n = read(), k = read();
  fact[0] = 1;
  for (int i = 1; i <= 1000000; ++i) fact[i] = 1ll * fact[i - 1] * i % mod;
  for (int i = 1, cur; i <= n; ++i) {
    a[i] = read();
    cur = top;
    while (cur && a[i] < a[stk[cur]]) --cur;
    if (cur) ch[stk[cur]][1] = i;
    if (cur < top) ch[i][0] = stk[cur + 1];
    stk[++cur] = i;
    top = cur;
  }
  dfs(stk[1], 0);
  printf("%d", f[stk[1]][k]);
  return 0;
}
